package com.zhouxiaoge.memcached;

import com.whalin.MemCached.MemCachedClient;
import com.whalin.MemCached.SockIOPool;

/**
 * @author 周明阳
 * email: gqzmy@outlook.com
 * Date: 2018-07-19 10:13
 */

public class MemcachedJava {
    public static void main(String[] args) {

        MemCachedClient mc = new MemCachedClient();
        /*服务器列表和其权重*/
        String[] servers = {"127.0.0.1:11211"};
        Integer[] weights = {3};
        /*获取socket连接池的实例对象*/
        SockIOPool sockIOPool = SockIOPool.getInstance();
        /*设置服务器信息*/
        sockIOPool.setServers(servers);
        sockIOPool.setWeights(weights);
        /*设置初始化连接数*/
        sockIOPool.setInitConn(5);
        /*设置最小连接数*/
        sockIOPool.setMinConn(5);
        /*设置最大连接数*/
        sockIOPool.setMaxConn(250);
        /*设置最大处理时间*/
        sockIOPool.setMaxIdle(1000 * 60 * 60 * 6);
        //设置主线程的睡眠时间
        sockIOPool.setMaintSleep(30);

        sockIOPool.setNagle(false);
        sockIOPool.setSocketTO(30);
        sockIOPool.setSocketConnectTO(0);
        sockIOPool.initialize();

        boolean set = mc.set("MemCachedKey", "MemCachedValue");
        System.out.println(set);
        System.out.println(mc.get("MemCachedKey"));

    }
}
